import {ScrollView, Text, View} from 'react-native';
import React, {Component} from 'react';
import BarcodeScanner from '../../common/barcode_scanner/BarcodeScanner';
import Screen from '../../common/screen/Screen';
export default class BarCode extends Component {
  constructor(props) {
    super(props);
    this.state = {
      name: '扫码',
      torchMode: 'off',
      cameraType: 'back',
      code: '',
    };
    this.barcodeReceived = this.barcodeReceived.bind(this);
  }

  barcodeReceived(e) {
    this.setState({
      code: e.data,
    });
  }

  render() {
    return (
      <View>
        <BarcodeScanner
          onBarCodeRead={this.barcodeReceived}
          style={{height: Screen.size.width, width: Screen.size.width}}
          torchMode={this.state.torchMode}
          cameraType={this.state.cameraType}
        />
        <ScrollView
          style={{
            minHeight: '20%',
            width: '100%',
            backgroundColor: 'white',
            marginTop: '5%',
            marginLeft: '1%',
            marginRight: '1%',
            padding: '1%',
          }}>
          <Text>{this.state.code}</Text>
        </ScrollView>
      </View>
    );
  }
}
